<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page isELIgnored="false"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>

<!-- Mirrored from www.zi-han.net/theme/hplus/table_bootstrap.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:20:03 GMT -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<base href="<%=basePath%>">
<title>李宁体育管理系统</title>
<!-- jsp文件头和头部 -->
<script type="text/javascript"
	src="js/plugins/zTree/3.5/jquery-1.4.4.min.js"></script>
<link type="text/css" rel="stylesheet"
	href="js/plugins/zTree/2.6/zTreeStyle.css" />
<script type="text/javascript"
	src="js/plugins/zTree/2.6/jquery.ztree-2.6.min.js"></script>
<link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
<link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
<link href="css/animate.min.css" rel="stylesheet">
<link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
<link href="css/plugins/chosen/chosen.css" rel="stylesheet">
<link href="css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"
          rel="stylesheet">
<!-- Sweet Alert -->
<style type="text/css">
footer {
	height: 50px;
	position: fixed;
	bottom: 0px;
	left: 0px;
	width: 100%;
	text-align: center;
}
</style>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>分配运营者菜单权限</h5>
					</div>
				</div>
			</div>

			<div class="ibox-content">
				<div class="row">

					<div class="col-sm-4">
						<div class="example-wrap">
							<ul id="tree" class="tree" style="overflow: auto;"></ul>
						</div>
					</div>
					<div class="col-sm-8">

						<form class="form-horizontal m-t" method="post" id="signupForm">
							<input type="hidden" name="id" id="id" value="${user.userId }" />
							<div class="form-group">
								<label class="col-sm-2 control-label">管理员名：</label>

								<div class="col-sm-4">
									<input class="form-control" type="text"
										value="${user.userName }" disabled>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">角色：</label>

								<div class="col-sm-4">
									<input class="form-control" type="text" id="roleName" name="roleName"
										value="" maxlength="25">
								</div>
								<span id="error_roleName" style="color: red">*</span>
							</div>
						 <div class="form-group">
                            <label class="col-sm-2 control-label">活动门店：</label>

                            <div class="col-sm-4">
                                   <select class="chosen-select form-control" name="storeId" id="storeId" data-placeholder="请选择门店" >
                                <option value=""></option>
                                <option value="">不选择任何门店</option>
                                <c:forEach items="${list }" var="mp">
                                    <option value="${mp.id }">${mp.name }</option>
                                </c:forEach>
                            </select>
                            </div>
                            <span id="error_storeId" style="color: red">只针对活动管理</span>
                        </div>
							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-3">
									<button class="btn btn-primary" type="button" onclick="save()">提交</button>
									&nbsp;<button class="btn btn-info" type="button" onclick="goback()">返回</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>

		</div>
	</div>
<script src="js/plugins/chosen/chosen.jquery.js"></script>
<script src="js/jquery.validate.js"></script>
<script src="js/jquery.serializeObject.js"></script>
	<script type="text/javascript">
	var config = {
	        ".chosen-select": {},
	        ".chosen-select-deselect": {allow_single_deselect: !0},
	        ".chosen-select-no-single": {disable_search_threshold: 10},
	        ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
	        ".chosen-select-width": {width: "95%"}
	    };
    var zTree;
    $(document).ready(function () {
                          
        var setting = {
            showLine: true,
            checkable: true
        };
        var zn = '${zTreeNodes}';
        var zTreeNodes = eval(zn);
        zTree = $("#tree").zTree(setting, zTreeNodes);
       
    });
    for (var selector in config)$(selector).chosen(config[selector]);
    var flage=false;
    
    //保存
   function save() {
    	if(flage){
        var nodes = zTree.getCheckedNodes();
        var tmpNode;
        var ids = "";
        for (var i = 0; i < nodes.length; i++) {
            tmpNode = nodes[i];
            if (i != nodes.length - 1) {
                ids += tmpNode.id + ",";
            } else {
                ids += tmpNode.id;
            }
        }
        var temp = {};
        var formParam = $('#signupForm').serializeArray();
        for (var i = 0; i < formParam.length; i++) {
            if (formParam[i].value != '') {
                temp[formParam[i].name] = formParam[i].value;
            }
        }
        var url = "<%=path%>/operator/toSaveOperatorRole";
        var postData;
        postData = {"roleName": JSON.stringify(temp), "menuIds": ids};
        $.post(url, postData, function (data) {
        	window.location.href="<%=path%>/operator/listOpeartor";
        },"json");
    	}else{
			$("#error_roleName").html("角色名重复或为空");
		}
    }
    
   $("#roleName").blur(function(){
   	var roleName=$("#roleName").val();
   	$("#error_roleName").html("");
   	if(roleName){
   		jQuery.ajax({
				type: "post",
			    url: "<%=path%>/user/toCheckRoleName",
			    dateType: "json",
			    data: {"roleName":roleName},
			    success: function (data) {
			    	if(data.status==400){
			    		$("#error_roleName").html(data.msg);
			    		flage=false;
			    	}else{
			    		$("#error_roleName").html("");
			    		flage=true;
			    	}
			    },
			});	
   	}
   });

    
   function goback() {
		window.location.href="<%=path%>/operator/listOpeartor";
	}
</script>
</html>